package edu.bbu.commonproject.desktop.gui.view.swing.file.lister;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import edu.bbu.commonproject.desktop.gui.view.swing.utils.Design;
import edu.bbu.commonproject.desktop.gui.view.swing.utils.TexturedPanel;
import edu.bbu.commonproject.desktop.gui.view.swing.utils.TransparentButton;

/**
 * The server file control panel.
 */
public class ServerFilesControlPanel extends JPanel
{
	/** The button panel texture image. */
	private Image buttonPanelTexture;
	
	/** The directory panel texture image. */
	private Image directoryPanelTexture;
	
	/** The back button icon. */
	private ImageIcon backButtonIcon;
	
	/** The new directory button icon. */
	private ImageIcon newDirectoryButtonIcon;
	
	/** The delete button icon. */
	private ImageIcon deleteButtonIcon;
	
	/** The upload button icon. */
	private ImageIcon downloadButtonIcon;
	
	/** The refresh button icon. */
	private ImageIcon refreshButtonIcon;
	
	/** The current directory label icon. */
	private ImageIcon currentDirectoryLabelIcon;
	
	/** The back button. */
	private TransparentButton backButton;
	
	/** The new directory button. */
	private TransparentButton newDirectoryButton;
	
	/** The delete button. */
	private TransparentButton deleteButton;
	
	/** The upload button. */
	private TransparentButton downloadButton;
	
	/** The current directory refresh Button. */
	private TransparentButton refreshButton;
	
	/** The current directory label. */
	private JLabel currentDirectoryLabel;
	
	/** The button panel. */
	private TexturedPanel buttonPanel;
	
	/** The current directory label. */
	private TexturedPanel currentDirectoryPanel;
	
	/**
	 * The contsructor.
	 */
	public ServerFilesControlPanel()
	{
		buttonPanelTexture = Design.FILELIST_CONTROL_BASETEXTURE;
		directoryPanelTexture = Design.FILELIST_CONTROL_NAMETEXTURE;
		backButtonIcon = new ImageIcon(Design.FILELIST_CONTROL_BACK);
		newDirectoryButtonIcon = new ImageIcon(Design.FILELIST_CONTROL_ADD);
		deleteButtonIcon = new ImageIcon(Design.FILELIST_CONTROL_DELETE);
		downloadButtonIcon = new ImageIcon(Design.FILELIST_CONTROL_DOWNLOAD);
		refreshButtonIcon = new ImageIcon(Design.FILELIST_CONTROL_REFRESH);
		currentDirectoryLabelIcon = new ImageIcon(Design.FILELIST_CONTROL_CURRDIR);
		
		this.setLayout(new BorderLayout());
		setComponents();
	}
	
	/**
	 * Setting up the components.
	 */
	private void setComponents()
	{
		buttonPanel = new TexturedPanel();
		buttonPanel.setTexture(buttonPanelTexture);
		buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 1));
		buttonPanel.setPreferredSize(new Dimension(500,32));
		
		backButton = new TransparentButton();
		backButton.setIcon(backButtonIcon);
		backButton.setFocusable(false);
		backButton.setPreferredSize(new Dimension(30,30));
		
		newDirectoryButton = new TransparentButton();
		newDirectoryButton.setIcon(newDirectoryButtonIcon);
		newDirectoryButton.setFocusable(false);
		newDirectoryButton.setPreferredSize(new Dimension(30,30));
		
		deleteButton = new TransparentButton();
		deleteButton.setIcon(deleteButtonIcon);
		deleteButton.setFocusable(false);
		deleteButton.setPreferredSize(new Dimension(30,30));
		
		downloadButton = new TransparentButton();
		downloadButton.setIcon(downloadButtonIcon);
		downloadButton.setFocusable(false);
		downloadButton.setPreferredSize(new Dimension(30,30));
		
		refreshButton = new TransparentButton();
		refreshButton.setIcon(refreshButtonIcon);
		refreshButton.setFocusable(false);
		refreshButton.setPreferredSize(new Dimension(30,30));

		buttonPanel.add(backButton);
		buttonPanel.add(newDirectoryButton);
		buttonPanel.add(deleteButton);
		buttonPanel.add(refreshButton);
		buttonPanel.add(downloadButton);
		
		currentDirectoryPanel = new TexturedPanel();
		currentDirectoryPanel.setTexture(directoryPanelTexture);
		currentDirectoryPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
		currentDirectoryPanel.setPreferredSize(new Dimension(500,20));

		currentDirectoryLabel = new JLabel();
		currentDirectoryLabel.setIcon(currentDirectoryLabelIcon);
		currentDirectoryPanel.add(currentDirectoryLabel);
		
		this.add(buttonPanel, BorderLayout.NORTH);
		this.add(currentDirectoryPanel, BorderLayout.SOUTH);
	}
	
	/**
	 * Setting the back button.
	 * @param backButton the new back button.
	 */
	public void setBackButton(TransparentButton backButton)
	{
		this.backButton = backButton;
	}
	
	/**
	 * Getting the back button.
	 * @return the back button.
	 */
	public TransparentButton getBackButton()
	{
		return backButton;
	}
	
	/**
	 * Setting the new directory button.
	 * @param newDirectoryButton the new directory button.
	 */
	public void setNewDirectoryButton(TransparentButton newDirectoryButton)
	{
		this.newDirectoryButton = newDirectoryButton;
	}
	
	/**
	 * Getting the new directory button.
	 * @return the new directory button.
	 */
	public TransparentButton getNewDirectoryButton()
	{
		return newDirectoryButton;
	}
	
	/**
	 * Setting the delete button.
	 * @param deleteButton the delete button.
	 */
	public void setDeleteButton(TransparentButton deleteButton)
	{
		this.deleteButton = deleteButton;
	}
	
	/**
	 * Getting the delete button.
	 * @return the delete button.
	 */
	public TransparentButton getDeleteButton()
	{
		return deleteButton;
	}
	
	/**
	 * Setting the download button.
	 * @param uploadButton the download button.
	 */
	public void setDownloadButton(TransparentButton downloadButton)
	{
		this.downloadButton = downloadButton;
	}
	
	/**
	 * Getting the download button.
	 * @return the download button.
	 */
	public TransparentButton getDownloadButton()
	{
		return downloadButton;
	}
	
	/**
	 * Setting the current directory label.
	 * @param currentDirectoryLabel the new directory label.
	 */
	public void setCurrentDirectoryLabel(JLabel currentDirectoryLabel)
	{
		this.currentDirectoryLabel = currentDirectoryLabel;
	}
	
	/**
	 * Getting the current directory label.
	 * @return the current directory label.
	 */
	public JLabel getCurrentDirectoryLabel()
	{
		return currentDirectoryLabel;
	}
	
	/**
	 * Setting the refresh button.
	 * @param refreshButton the button.
	 */
	public void setRefreshButton(TransparentButton refreshButton)
	{
		this.refreshButton = refreshButton;
	}
	
	/**
	 * Getting the refresh button.
	 * @return the refresh button.
	 */
	public TransparentButton getRefreshButton()
	{
		return refreshButton;
	}
}
